<?php

    /**
     * Abstract
     *
     * @package      Core
     * @subpackage   Selector
     *
     * @license      GNU Lesser General Public Licence see LICENCE-LGPL file or http://www.gnu.org/licenses/lgpl.html
     */
	abstract class Core_Selector_Abstract extends Core_Object
	{

    ////////////////////////////////////////////////////////////////////////////
	//                                Variables                               //
	////////////////////////////////////////////////////////////////////////////

		/**
		 * Zend_Registry object
		 *
		 * @var Zend_Registry
		 */
		protected $_registry = null;

	    /**
         * Path to the class
         *
         * @var string
         */
        protected $_path;

	    /**
         * Name of the module
         *
         * @var string
         */
        protected $_module  = '';

	    /**
         * Internal representation of the action
         *
         * @var string
         */
        protected $_resource  = '';

	////////////////////////////////////////////////////////////////////////////
	//                            Getters / Setters                           //
	////////////////////////////////////////////////////////////////////////////

		/**
         * Returns the path to the class
         *
         * @return      string
         */
        public function getPath()
		{
			return $this->_path;
		}

		/**
         * Returns the module's name
         *
         * @return      string
         */
        public function getModule()
		{
			return $this->_module;
		}

		/**
         * Returns the internal representation of the action
         *
         * @return      string
         */
        public function getResource()
		{
			return $this->_resource;
		}

	////////////////////////////////////////////////////////////////////////////
	//                                 Methods                                //
	////////////////////////////////////////////////////////////////////////////

	    /**
		 * Constructor
		 *
		 * @param       string      $selector
		 * @throws      Core_Exception
		 * @throws		Core_ArgumentException
		 * @throws		Core_ArgumentNullException
	     */
	    public function __construct($selector)
		{
            if ($selector === null) {
				throw new Core_ArgumentNullException('selector is a null reference');
			}

            if (strlen(trim($selector)) == 0) {
				throw new Core_ArgumentException('selector is a zero-length string');
			}

			$this->_registry = Zend_Registry::getInstance();

            if (preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.]+)$/", $selector, $m)) {
                if ($m[1] != '' && $m[2] != '') {
                    $this->_module = $m[2];
                } else {
                    $this->_module = Core_Context::get();
                }

                $this->_resource = $m[3];

                $this->_createPath();
            } else {
                throw new Core_Exception('Invalid zone selector syntax : '. $selector);
            }
	    }

        /**
         * Destructor
         */
        public function __destruct()
        {
            unset($this);
        }

	////////////////////////////////////////////////////////////////////////////
	//                            Protected methods                           //
	////////////////////////////////////////////////////////////////////////////

	    /**
         * Sets the real path to the defined file
         *
         * @return      void
         */
        abstract protected function _createPath();
	}
